package com.piccolo.wrapper.client.component;

import com.piccolo.wrapper.client.component.Overlay.PBoundsOverlay;

/**
 * @author Maria Patrickson
 * @version 1.0
 */
public class PBounds 
{
	private PBoundsOverlay overlay;

	/**
	 * Constructs a PBounds object at the given coordinates with the given dimensions.
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 */
	public PBounds(double x, double y, double width, double height)
	{
		overlay = PBoundsOverlay.create(x, y, width, height);
	}

	/**
	 * Creates a copy of the provided PBounds.
	 * @param bounds
	 */
	public PBounds(PBounds bounds)
	{
		overlay = PBoundsOverlay.create(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight());
	}

	/**
	 * Creates a PBounds with the supplied JavaScipt overlay object.
	 * @param overlay
	 */
	public PBounds(PBoundsOverlay overlay) 
	{
		this.overlay = overlay;
	}

	/**
	 * @return The JavaScript overlay object for this object.
	 */
	public PBoundsOverlay getOverlay() 
	{
		return overlay;
	}

	/**
	 * @return The x coordinate for this object
	 */
	public double getX() 
	{
		return overlay.getX();
	}

	/**
	 * @return The y coordinate for this object
	 */
	public double getY() 
	{
		return overlay.getY();
	}

	/**
	 * @return The width of this bounds
	 */
	public double getWidth() 
	{
		return overlay.getWidth();
	}

	/**
	 * @return The height of this bounds
	 */
	public double getHeight() 
	{
		return overlay.getHeight();
	}
	
	public boolean isEmpty()
	{
		return overlay.isEmpty();
	}
	
	public void add(double x, double y, double width, double height)
	{
		overlay.add(x, y, width, height);
	}

	public boolean contains(double x, double y)
	{
		return overlay.contains(x, y);
	}

	public boolean intersectes(PBounds bounds)
	{
		return overlay.intersects(bounds);
	}
}
